namespace SharpTalk.Client.WpfApplication
{
    using Core;
    using Services;
    using System;
    using System.Linq;

    /// <summary>
    /// Extensions methods
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// Determines if the chatroom details can be edited by
        /// the current user
        /// </summary>
        /// <param name="chatroom"></param>
        /// <returns></returns>
        public static bool CanEdit(this ChatRoomDetails chatroom)
        {
            return chatroom.Owner != Guid.Empty &&
                ApplicationServices.Current.CurrentUser !=null &&
                ApplicationServices.Current.CurrentUser.Guid == chatroom.Owner;
        }
        /// <summary>
        /// Determines if a chatroom is already in a discussion
        /// </summary>
        /// <param name="chatroom"></param>
        /// <returns>True if already joined otherwise false</returns>
        public static bool AlreadyJoined(this ChatRoomDetails chatroom)
        {
            return ApplicationServices.Current.Discussions.Where(d => d.Chatroom == chatroom).Any();
        }
    }
}